package com.br.estoque.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.br.estoque.bean.Tipo;

public class TipoDAO extends DataUtils {
	public List<Tipo> getAll() {
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		List<Tipo> lista = new ArrayList<Tipo>();
		Tipo tipo = null;
		try{
			conn = getConnection();
			stmt = conn.prepareStatement("SELECT * FROM tipo;");
			rs = stmt.executeQuery();
			while(rs.next()){
				tipo = new Tipo();
				tipo.setId(rs.getInt("codigo"));
				tipo.setTipo(rs.getString("tipo"));
				lista.add(tipo);
			}
		
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				conn.close();
				stmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		return lista;
	}
}
